﻿using System.Text;
using MossDAL.DotNet;
using MossDAL.Samples;

namespace linqforlistitems
{
    public static class ApplicationQueries
    {
        public static string GetSiteGalleryItems()
        {
            StringBuilder sb = new StringBuilder();
            //<q>
            //  <Query>
            //      <Where>
            //          <Eq>
            //              <FieldRef Name='show_x0020_in_x0020_viewer' />
            //              <Value Type='Boolean'>1</Value>
            //          </Eq>
            //      </Where>
            //      <OrderBy>
            //          <FieldRef Name='display_x0020_order' Ascending='True' />
            //      </OrderBy>
            //  </Query>
            sb.Append(
                CamlFactory.CreateQuery(
                    CamlFactory.CreateWhereClause(
                        CamlFactory.CreateEqualCriteria(
                            CamlFactory.CreateBooleanField("1", "show_x0020_in_x0020_viewer")
                            )
                        ),
                    CamlFactory.CreateOrderByClause(
                        CamlFactory.CreateOrderByFieldRef("display_x0020_order", CamlFactory.OrderByType.Ascending)
                     )
                 )
            );
            //<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /><FieldRef Name='project' /><FieldRef Name='client' /><FieldRef Name='ImageWidth' /><FieldRef Name='ImageHeight' /><FieldRef Name='Description' /><FieldRef Name='show_x0020_in_x0020_viewer' /><FieldRef Name='display_x0020_order' /><FieldRef Name='url' /></ViewFields>
            sb.Append(new SiteGalleryListItem().ViewFields());
            //<QueryOptions></QueryOptions></q>
            sb.Append(CamlFactory.CreateEmptyQueryOptions());
            return sb.ToString();
        }
    }
}
